package com.jjkj.environmental.environmental.bean.response

import com.jjkj.environmental.environmental.exception.DataLoadException
import com.jjkj.environmental.environmental.utils.MyLog
import java.net.URLDecoder
import java.util.regex.Pattern

class SoapResponse {
    private val regex = "<message>([\\s\\S]*)</message>"
    var body: String? = null
        get() {
            val ret = URLDecoder.decode(field, "UTF-8")
            MyLog.i(ret)
            if (!ret.contains("<code>1</code>")) {
                val pattern = Pattern.compile(regex)
                val matcher = pattern.matcher(ret)
                if (matcher.find() && matcher.groupCount() >= 1) {
                    throw DataLoadException(matcher.group(1))
                } else {
                    throw DataLoadException("服务器返回异常")
                }
            }
            return ret
        }

}